<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<%@ include file="header.jsp"%>
	<meta charset="UTF-8">
	<title>Insert title here</title>
</head>
<body>	
	<%-- ${pageInfo} --%>
	${user.name}
	<a href="${path}/user?method=logout">退出</a>
	<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>ID</td>
			<td>名字</td>
			<td>密码</td>
			<td>年龄</td>
			<td>邮箱</td>
			<td>删除</td>
		</tr>
		<c:forEach items="${pageInfo.list}" var="user">
			<tr>
				<td>${user.id}</td>
				<td>${user.name}</td>
				<td>${user.password }</td>
				<td>${user.age}</td>
				<td>${user.email }</td>
				<td><a href="javascript:void(0)" onclick="deleteById(${user.id})">删除</a></td>
			</tr>
		</c:forEach>
	</table>
	<nav aria-label="Page navigation">
	  <ul class="pagination">
	    <li>
	      <a href="#" aria-label="Previous">
	        <span aria-hidden="true">&laquo;</span>
	      </a>
	    </li>
	    <c:forEach begin="1" end="${pageInfo.totalPage}" var="i">
		    <li><a href="${pageContext.request.contextPath}/user?method=selectByPage&pageNo=${i}">${i}</a></li>
	    </c:forEach>
	 
	    <li>
	      <a href="#" aria-label="Next">
	        <span aria-hidden="true">&raquo;</span>
	      </a>
	    </li>
	  </ul>
	</nav>
	
	<script type="text/javascript">
		function deleteById(id) {
			layer.confirm(
				'您确认要删除么？',
				{icon : 3},
				function(index){//点击确认触发
					$.post(
						'${path}/user?method=deleteById',
						{'id' : id},
						function(jsonObj) {
							console.log(jsonObj)
							if(jsonObj.isOk) {
								// alert(jsonObj.msg);
								// mylayer.okMsg(jsonObj.msg);
								// location.href = '${path}/user';
								
								mylayer.okUrl(jsonObj.msg, '${path}/user');
							}
						},
						'json'
					);
				},
				function(index) {//点击取消触发
					console.log("点击了取消");
				}
			);
				
		}
			
			

	</script>
</body>
</html>